﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'auction';
domain = 'http://img1.chinalaohu.com';


//加价幅度
function addpfunc(jg){
	if (jg lte 50){
		addp = 1;
	}
	else if(jg gt 50 and jg lte 100){
		addp = 2;
	}
	else if(jg gt 100 and jg lte 500){
		addp = 5;
	}
	else if(jg gt 500 and jg lte 1000){
		addp = 10;
	}
	else if(jg gt 1000 and jg lte 2000){
		addp = 20;
	}
	else if(jg gt 2000 and jg lte 5000){
		addp = 50;
	}
	else if(jg gt 5000 and jg lte 10000){
		addp = 100;
	}
	else if(jg gt 10000 and jg lte 20000){
		addp = 200;
	}
	else if(jg gt 20000 and jg lte 50000){
		addp = 500;
	}
	else if(jg gt 50000 and jg lte 200000){
		addp = 1000;
	}
	else {
		addp = 2000;
	}
	return addp;
}
</cfscript>
<cfparam name="platform" default="0" >

<cffunction name="show" access="remote" returntype="any" returnFormat="json">

<cfscript>
j = {"success":"0"};
isLead = 0;
isProxy = 0;
proxyPrice = 0;
</cfscript>
<cfif isdefined('aid')>
	
  <cfif isdefined('UUID') and LEN(UUID) gte 32>
    <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" />
    <cfif uuidgetuid.recordcount gt 0>
      <!---<cfinvoke component="app.cfc.user" method="userCreditLimit" returnvariable="credit" aid="#aid#" uid="#uuidgetuid.uid#" />--->
      <cfinvoke component="app.cfc.credit" method="userCreditLimit" returnvariable="credit" aid="#aid#" uid="#uuidgetuid.uid#" />
      <!---是否领先--->
      <cfquery datasource="#DB#" name="uidisLead">
      select uid,is_bid
      from auction_userlastbid
      where aid = #aid# AND uid = #uuidgetuid.uid#
      </cfquery>
      <!---代理价--->
      <cfquery datasource="#DB#" name="haveproxy">
      SELECT bidproxy,uid
      from auction_userbidproxy
      where aid = #aid# and uid=#uuidgetuid.uid# order by xid desc limit 1
      </cfquery>
      <cfscript>
      if (uidisLead.recordcount gt 0){
        isLead = uidisLead.is_bid;
      }
      if (haveproxy.recordcount gt 0){
        isProxy = 1;
        proxyPrice = haveproxy.bidproxy;
      }
      </cfscript>
      <cfscript>
      //uuid未传给服务端或者uuid己失效，isLogin返回0 uuid 正确 isLogin返回1
      if (len(uuidgetuid.realname) gt 0){
        name = uuidgetuid.realname;
      }
      else {
        name = uuidgetuid.mobile; 
      }
      /*
      //显示会员级别名称
      switch(uuidgetuid.urank){
        case 1:
          urankname = '';
        
      
      }
      */
function urankfunc(urank){
	switch(urank){
		case 0:
			return '未注册会员';
			break;
		case 1:
			return '注册会员';
			break;
		case 2:
			return '一钻会员';
			break;
		case 3:
			return '二钻会员';
			break;
		case 4:
			return '三钻会员';
			break;
		case 5:
			return '四钻会员';
			break;
		case 6:
			return '五钻会员';
			break;
		case 7:
			return '一皇冠';
			break;
		case 8:
			return '二皇冠';
			break;
	}
}
			
			
      userjson = {"isLogin":"1","name":name,"urank":urankfunc(uuidgetuid.urank),"state":uuidgetuid.ustatus};
      </cfscript>
    <cfelse>
			<cfscript>
      //uuid未传给服务端或者uuid己失效，isLogin返回0 uuid 正确 isLogin返回1
      userjson = {"isLogin":"0"};
      </cfscript>
    </cfif>
  <cfelse>
    <cfscript>
		//uuid未传给服务端或者uuid己失效，isLogin返回0 uuid 正确 isLogin返回1
		userjson = {"isLogin":"0"};
		</cfscript>
	</cfif>
  
  
  
	<cfquery datasource="#DB#" name="auctionshow">
  select *,if(lastprice = 0,startprice,lastprice) as showprice
  from auction
  where aid = #aid#
  </cfquery>
  <cfif auctionshow.recordcount gt 0>
  	<!---图片--->
    <cfquery datasource="#DB#" name="agimglist">
    select img_url,img_original
    FROM
    auction_gallery
    WHERE
    aid = #aid#
	
	order by  agid asc
    </cfquery>
    <!---拍卖出价记录--->
    <cfquery datasource="#DB#" name="abithistory">
    SELECT
    u.mobile as nick,
    a.bid,
    a.bid_dt,
	a.is_bid
    FROM
    auction_userbid a left outer join user_base u on a.uid=u.uid
    WHERE
    a.aid = #aid#
    ORDER BY
    a.aubid DESC
    limit 10
    </cfquery>
    
  	<cfscript>
		j = {"success":"1","serverTime":datetimeformat(now(),'yyyy-mm-dd HH:nn:ss')};
		history = arraynew(1);
		</cfscript>
    <cfif abithistory.recordcount gt 0>
    	<cfoutput query="abithistory">
      	
				<cfscript>
				if (isdefined('uuidgetuid') and nick eq uuidgetuid.mobile){
					//nickname = nick;
					nickname = left(nick,3) & '*****' & right(nick,3);
					mine = 1;
				}
				else {
					nickname = left(nick,3) & '*****' & right(nick,3);
					mine = 0;
				}
				
        historyjson = {
          "name":nickname,
          "time":datetimeformat(bid_dt,'yyyy-mm-dd HH:nn:ss'),
          "price":bid,
		"mine": mine,
		"state":is_bid
        };
				arrayappend(history,historyjson);
        </cfscript>    
      </cfoutput>
    </cfif>
    
    <cfif isdefined('uuidgetuid')>
    
    <!---<cfdump var="#uuidgetuid#">--->
    
    </cfif>
    
    <cfoutput query="auctionshow">
			<cfscript>
			//图片数组
			if (agimglist.recordcount gt 0){
				imgUrllist = ValueList(agimglist.img_url);
				
				imgUrl = listtoarray(imgUrllist);
				for (i=1;i lte arraylen(imgUrl);i=i+1){
					if (findnocase('http://',imgUrl[i]) eq 0){
						
switch(platform){
	case 0:
		lightboxUrl = domain & imgUrl[i];
		if (left(imgUrl[i],8) eq '/upload/' and left(imgUrl[i],13) neq '/upload/adio/'){
			lightboxUrl = domain & replacenocase(imgUrl[i],'/upload/','/upload/adio/');
		}						
		break;
	case 1:
		lightboxUrl = domain & imgUrl[i];
		if (left(imgUrl[i],8) eq '/upload/' and left(imgUrl[i],13) neq '/upload/ios/'){
			lightboxUrl = domain & replacenocase(imgUrl[i],'/upload/','/upload/ios/');
		}						
		break;
}
						
						imgUrl[i] = lightboxUrl;
					}
				}
				
				imgOriginallist = valuelist(agimglist.img_original);
				imgOriginal = listtoarray(imgOriginallist);
				for (i=1;i lte arraylen(imgOriginal);i=i+1){
					if (findnocase('http://',imgOriginal[i]) eq 0){
						
switch(platform){
	case 0:
		bigUrl = domain & imgOriginal[i];
		if (left(imgOriginal[i],8) eq '/upload/' and left(imgOriginal[i],13) neq '/upload/adio/'){
			bigUrl = domain & replacenocase(imgOriginal[i],'/upload/','/upload/adio/');
		}						
		break;
	case 1:
		bigUrl = domain & imgOriginal[i];
		if (left(imgOriginal[i],8) eq '/upload/' and left(imgOriginal[i],13) neq '/upload/ios/'){
			bigUrl = domain & replacenocase(imgOriginal[i],'/upload/','/upload/ios/');
		}						
		break;
}
						
						
						
						imgOriginal[i] = bigUrl;
					}
					
				}
				
			}
			
			if (not isdefined('credit')){
				credit = 0;
			}
			if (auctionshow.bids eq 0){
				isOrigin = 1;
			}
			else {
				isOrigin = 0;
			}
			
		if(isLead eq 1){
			//在客户端中，可用额度减去了当前价，或者代理价（不该减去），在此加回来，避免客户端显示错误
			if(isProxy eq 1){
				credit = credit+proxyPrice;
			}else{
				credit = credit+showprice;
			}
		}
      auctionjson = {
        "aID":aid,
				"imgUrl":imgUrl,
				"bigImgUrl":imgOriginal,
				"name":auction,
				"auctionCode": acode,
				"price":showprice, 
				"credit":Numberformat(credit,'_.__'),
				"servicePrice":servicefee,
				"rank":addpfunc(showprice),
				"isOrigin":isOrigin,
				"isLead":isLead,
				"isProxy":isProxy,
				"proxyPrice":proxyPrice
      };

//拍卖进度
if (DateCompare(now(), endtime) gte 0){
	auctionType = 2;//成交
	structappend(auctionjson,{"dealTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), starttime) gte 0){
	auctionType = 1;//拍卖
	structappend(auctionjson,{"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn:ss')});
	
}
else if (DateCompare(now(), prevtime) gte 0){
	auctionType = 0;//预展
	structappend(auctionjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
	structappend(auctionjson,{"preETime":datetimeformat(starttime,'yyyy-mm-dd HH:nn')});
}
else {
	auctionType = -1;//待展
	structappend(auctionjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
}
structappend(auctionjson,{"auctionType":auctionType});

			
      </cfscript>
    
    
    </cfoutput>
    <cfscript>
		StructAppend(j,{"user":userjson});
		StructAppend(j,{"history":history});
		StructAppend(j,{"auction":auctionjson});
		</cfscript>
    
  
  <cfelse>
  	<!---,"msg":"错误的ID"--->
		<cfset j = {"success":"0"}>
  </cfif>
</cfif>

<cfscript>
if (isdefined('dump')){
	writedump(j);	
}
//return j;
//j = createObject("java", "org.json.JSONObject").init(j).toString();
j = createObject("component",'cfjson').encode(j);
return j;
</cfscript>
</cffunction>

<!---拍品详细介绍--->
<cffunction name="getabrief" access="remote" returntype="query">
<cfquery datasource="#DB#" name="rs">
select a.abrief,a.zuozhe,a.xuexiao,a.chizhi,a.leixin,a.guige,a.baozhuang,b.astid
from auction a  left outer join auction_special b on a.asid=b.asid
where aid = #aid#
</cfquery>
<cfreturn rs>
</cffunction>

<!---拍品价格--->
<cffunction name="getshowprice" access="remote" returntype="any" returnFormat="json">
	<cfset rs = {"success":"0"}>
  <cftry>
<cfquery datasource="#DB#" name="getshowprice">
select if(lastprice = 0,startprice,lastprice) as showprice,bids
from auction
where aid = #aid#
</cfquery>


	<cfscript>
	isProxy = 0;
	isLead = 0;
	credit = 0;
	proxyPrice = 0;
	if (getshowprice.bids eq 0){
		isOrigin = 1;
	}
	else {
		isOrigin = 0;
	}
	</cfscript>
	<cfif isdefined('uuid') and len(uuid) gte 32>
  <!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" />
		<cfif uuidgetuid.recordcount neq 1>
    	<!---"msg":"用户ID错误"--->
      <cfset rj = {"success":"0","errCode":"0"}>
    <cfelse>
    	<cfquery datasource="#DB#" name="uidaidproxy">
      SELECT bidproxy,uid
      from auction_userbidproxy
      where aid = #aid# AND uid = #uuidgetuid.uid#
      </cfquery>
      <cfinvoke component="app.cfc.credit" method="userCreditLimit" returnvariable="userCreditLimit" aid="#aid#" uid="#uuidgetuid.uid#" />
      <!---是否领先--->
      <cfquery datasource="#DB#" name="uidisLead">
      select uid,is_bid
      from auction_userlastbid
      where aid = #aid# AND uid = #uuidgetuid.uid#
      </cfquery>
      <cfscript>
      if (uidisLead.recordcount gt 0){
        isLead = uidisLead.is_bid;
      }
			if (uidaidproxy.recordcount gt 0){
				isProxy = 1;
				proxyPrice = uidaidproxy.bidproxy;
			}
      credit = userCreditLimit;
      </cfscript>
      
    </cfif>  
  </cfif>
	
  
  <cfscript>
	if(isLead eq 1){
		//在客户端中，可用额度减去了当前价，或者代理价（不该减去），在此加回来，避免客户端显示错误
		if(isProxy eq 1){
			credit = credit+proxyPrice;
		}else{
			credit = credit+getshowprice.showprice;
		}
	}
	if (getshowprice.recordcount gt 0){
		rs = {"success":"1","price": numberformat(getshowprice.showprice,'_.__'),"proxyPrice":proxyPrice,"isProxy":isProxy,"isLead":isLead,"credit":credit,"isOrigin":isOrigin};
	}
	rs = createObject("component",'cfjson').encode(rs);
	return rs;
	</cfscript>
	
  <cfcatch type="any">
		<cfscript>
    rs = {"success":"0"};
    rs = createObject("component",'cfjson').encode(rs);
    return rs;
    </cfscript>
  </cfcatch>
	</cftry>
</cffunction>

<!---获取历史竞价接口--->
<cffunction name="getbidlog" access="remote" returntype="any" returnFormat="json">
<cfscript>
j = {"success":"1"};
//j = {"success":"1","serverTime":datetimeformat(now(),'yyyy-mm-dd HH:nn:ss')};
history = arraynew(1);
</cfscript>
<cfif isdefined('aid')>
  <cfif isdefined('UUID') and LEN(UUID) gte 32>
    <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" uuid="#uuid#" />
	</cfif>
	<!---拍卖出价记录--->
  <cfquery datasource="#DB#" name="abithistory">
  SELECT
  u.mobile as nick,
  a.bid,
  a.bid_dt,
  a.is_bid
  FROM
  auction_userbid a left outer join user_base u on a.uid=u.uid
  WHERE
  a.aid = #aid#
  ORDER BY
  a.bid_dt DESC,aubid desc
  limit 10
  </cfquery>
	<cfscript>
  
  </cfscript>
  <cfif abithistory.recordcount gt 0>
    <cfoutput query="abithistory">
      
      <cfscript>
      if (isdefined('uuidgetuid') and nick eq uuidgetuid.mobile){
        //nickname = nick;
        nickname = left(nick,3) & '*****' & right(nick,3);
        mine = 1;
      }
      else {
        nickname = left(nick,3) & '*****' & right(nick,3);
        mine = 0;
      }
      
      historyjson = {
        "name":nickname,
        "time":datetimeformat(bid_dt,'yyyy-mm-dd HH:nn:ss'),
        "price":bid,
        "mine": mine,
		"state":is_bid
      };
      arrayappend(history,historyjson);
			j = {"success":"1","history":history};
      </cfscript>    
    </cfoutput>
  <cfelse>
	<!--- 没有记录 --->
	<cfoutput>
		<cfscript>
			j = {"success":"1","history":history};
		</cfscript>
	</cfoutput>
  </cfif>
<cfelse>
	<!---,"msg":"错误的ID"--->
	<cfset j = {"success":"0","errCode":"0"}>
</cfif>
<cfscript>
j = createObject("component",'cfjson').encode(j);
return j;
</cfscript>
</cffunction>


</cfcomponent>